from collections.abc import Iterable
list1 = []
for  i in  range(100):
    list1.append(i)
# print(list1)
d = {"name":"jack","age":14,"address":"shanghai"}

for key in d: # 默认是迭代key
    print("key: ",key)

for value in d.values(): # 迭代Value的情况
    print("Value: ",value)

for key,value in d.items(): # 同时迭代key和value
    print("key: ",key,"value: ",value)

for ch in "abcdefg": #字符串也是可迭代对象
    print("ch: ",ch)


if(isinstance("abc" ,(Iterable))): # 判断一个对象是否是可迭代对象
    print(True)

print(isinstance('aaa' ,(str,int)))


for i, value in enumerate(list1): # 变成下标-值的方式
    print("i: ",i,"--value:",value)


for i, value in enumerate((1,2,3,45,5,7,9)): # 变成下标-值的方式
    print("i: ",i,"--value:",value)


# 可以同时迭代多个变量
for x, y,z in[(1,2,3),(4,5,6)]:
    print(x,y,z)

#----------practice----------------------------------

def findMinAndMax(L):
    if not L:
        return (None,None)
    max = float('-inf') # 定义为无限小
    min = float('inf') # 定义为无限大
    for x in L:
        if x > max:
            max = x;
        if x < min:
            min = x;
    return (min,max)

# 测试
if findMinAndMax([]) != (None, None):
    print('测试失败!')
elif findMinAndMax([7]) != (7, 7):
    print('测试失败!')
elif findMinAndMax([7, 1]) != (1, 7):
    print('测试失败!')
elif findMinAndMax([7, 1, 3, 9, 5]) != (1, 9):
    print('测试失败!')
else:
    print('测试成功!')

for x,y,z in[[1,2,3]]: #同时迭代三个元素
    print(x,y,z)